<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <!--<link rel="stylesheet" type="text/css" href="/easyui/themes/metro/easyui.css"/>-->
    <!-- TopJUI框架样式 -->
    <link type="text/css" href="/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/topjui/themes/default/topjui.bluelight.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- layui框架样式 -->
    <link type="text/css" href="/static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <link type="text/css" href="/topjui/css/myui.css" rel="stylesheet"/>
    <script type="text/javascript" src="/static/public/js/topjui.config.js"></script>
    <!-- layui框架js -->
    <script type="text/javascript" src="/static/plugins/layui/layui.js" charset="utf-8"></script>
    <script src="/easyui/jquery.min.js"></script>
    <script src="/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/topjui/js/sysutils.js"></script>
</head>

<body>

<table id="rowgrid" class="topjui-datagrid"></table>

<script type="text/javascript" charset="utf-8" th:inline="none">
    var listgrid;
    $(function(){
        listgrid = $('#rowgrid').datagrid({
            url:"/sys/databaklist",
            method:'get',
            fit : true,
            fitColumns : true,
            border : false,
            pagination : false,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'desc',
            checkOnSelect : true,
            selectOnCheck : true,
            nowrap : false,
            columns:[[
                {
                    field:'id',
                    title:'编号',
                    width:50,
                    checkbox : true
                }, {
                    field:'filename',
                    title:'表名称',
                    sortable:true,
                    width:60
                }, {
                    field:'crtime',
                    title:'创建日期',
                    width:120
                }, {
                    field:'size',
                    title:'文件大小',
                    width:40
                }, {
                    field : 'action',
                    title : '操作',
                    width : 30,
                    align:'center',
                    formatter : function(value, row, index) {
                        return formatString('<img onclick="downloadFileByForm(\'{0}\');" style="cursor:pointer" src="{1}" title="下载"/>&nbsp;&nbsp;&nbsp;<img style="cursor:pointer" onclick="list_deleteFun(\'{2}\');" src="{3}"/>', row.id, '/static/admin/images/filesave.png',  row.id, '/static/admin/images/edit_remove.png');
                    }
                }
            ]],
            toolbar:[{
                text:'数据库备份',
                iconCls:'fa fa-save',
                btnCls: 'topjui-btn-normal',
                handler:function(){
                    list_bfFun();
                }
            }]
        });
    });

    function list_bfFun() {
        $.ajax({
            url: '/sys/databasebackup',
            dataType: 'json',
            success: function (r) {
                if (r.statusCode == '200') {
                    listgrid.datagrid('load');
                    listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
                }
                $.messager.show({
                    title: r.title,
                    msg: r.message
                });
            }
        });
    }

    //删除文件
    function list_deleteFun() {
        listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $.messager.confirm('确认', '您是否要删除当前选中的项目？', function (r) {
            if (r) {
                $.ajax({
                    url: '/sys/databaserm',
                    dataType: 'json',
                    data: {
                        id: id
                    },
                    success: function (r) {
                        if (r.statusCode == '200') {
                            listgrid.datagrid('load');
                            listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
                        }
                        $.messager.show({
                            title: r.title,
                            msg: r.message
                        });
                    }
                });
            }
        });
    }

    // 模拟表单提交同步方式下载文件
    // 能够弹出保存文件对话框
    function downloadFileByForm(filename) {
        //var url = "/sys/tablebak";
        var url = "/sys/datadown";
        var form = $("<form></form>").attr("action", url).attr("method", "post");
        form.append($("<input></input>").attr("type", "hidden").attr("name", "filename").attr("value", filename));
        form.appendTo('body').submit().remove();
    }
</script>

</body>
</html>